package com.ruoyi.sgsc.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sgsc.domain.shoppingcarts;
import com.ruoyi.sgsc.service.IshoppingcartsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 购物车Controller
 * 
 * @author wy
 * @date 2024-09-29
 */
@Anonymous
@RestController
@RequestMapping("/sgsc/shoppingcarts")
public class shoppingcartsController extends BaseController
{
    @Autowired
    private IshoppingcartsService shoppingcartsService;

    /**
     * 查询购物车列表
     */

    @GetMapping("/list")
    public TableDataInfo list(shoppingcarts shoppingcarts)
    {
//        startPage();
        List<shoppingcarts> list = shoppingcartsService.selectshoppingcartsList(shoppingcarts);
        return getDataTable(list);
    }

    /**
     * 导出购物车列表
     */

    @PostMapping("/export")
    public void export(HttpServletResponse response, shoppingcarts shoppingcarts)
    {
        List<shoppingcarts> list = shoppingcartsService.selectshoppingcartsList(shoppingcarts);
        ExcelUtil<shoppingcarts> util = new ExcelUtil<shoppingcarts>(shoppingcarts.class);
        util.exportExcel(response, list, "购物车数据");
    }

    /**
     * 获取购物车详细信息
     */

    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return success(shoppingcartsService.selectshoppingcartIDByUserId(userId));
    }

    /**
     * 根据userId获取购物车列表
     * @param userId
     * @return
     */
    @GetMapping(value = "/userId/{userId}")
    public AjaxResult getInfoByUserId(@PathVariable("userId") Long userId)
    {
        return success(shoppingcartsService.selectshoppingcartsByUserId(userId));
    }


    /**
     * 新增购物车
     */

    @PostMapping
    public AjaxResult add(@RequestBody shoppingcarts shoppingcarts)
    {
        return toAjax(shoppingcartsService.insertshoppingcarts(shoppingcarts));
    }

    /**
     * 修改购物车
     */

    @PutMapping
    public AjaxResult edit(@RequestBody shoppingcarts shoppingcarts)
    {
        return toAjax(shoppingcartsService.updateshoppingcarts(shoppingcarts));
    }

    /**
     * 删除购物车
     */

	@DeleteMapping("/{cartIds}")
    public AjaxResult remove(@PathVariable Long[] cartIds)
    {
        return toAjax(shoppingcartsService.deleteshoppingcartsByCartIds(cartIds));
    }
}
